﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AuctionSystem.AuctionService;


namespace AuctionSystem
{
    public partial class Index : Form
    {
        private static AuctionServiceClient client;
        private static User user;
        public Index()
        {
            InitializeComponent();
            startUpMethode();
        }
        private void startUpMethode()
        {
            client = new AuctionServiceClient();
            listBox1.DataSource = client.GetAllAuctions();
            listBox1.DisplayMember = "Title";


        }
        private void btn_exit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void listBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            Auction temAuction = (Auction)listBox1.SelectedItem;
            try
            {
                    listBox2.DataSource = temAuction.Items;
                    listBox2.DisplayMember = "Title";
                    listBox2.ValueMember = "Description";


            }
            catch (NullReferenceException)
            {
                MessageBox.Show("There's no items in the selected auction");
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Item tempItem = (Item)listBox2.SelectedItem;
            if (tempItem != null)
            {
                ShowArt showart = new ShowArt(tempItem, user);
                showart.Show();
            }
            else
            {
                MessageBox.Show("pick an auction and an item");
            }
        }
    }
}
